<template>
    <!-- 技术交底 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->

            <!-- 表格 -->
            <list-table
                ref="table"
                :page-keys="['pageNum', 'pageSize', 'total']"
                :columns="columns"
                :start-index="0"
                :request="loadData"
                :export-permission="{ select: 'tm_012_exp_06', all: 'tm_012_exp_06' }"
                :statisticsConfig="{use: true, temp: statisticsTemp}"
                :export-config="{
                    use: true,
                    all: '技术交底列表-导出全部',
                    select: '技术交底列表-导出选中',
                    customColumns
                }"
            >
                <a-button
                    slot="prefix"
                    class="mb12"
                    icon="plus"
                    type="primary"
                    @click="handleManage(2)"
                    v-btnPermission="'tm_012_add_01'"
                    v-if="hideBuquBtn()"
                    >新增</a-button
                >
                <template slot="actions" slot-scope="text, record">
                    <MoreButton>
                    <a @click="handleManage(0, record)" v-btnPermission="'tm_012_loo_04'">查看</a>
                    <!-- 编辑 -->
                    <template v-btnPermission="'tm_012_edi_02'" v-if="hideBuquBtn()">
                        <a @click="handleManage(1, record)">编辑</a>
                    </template>
                    <!-- 导出 -->
                    <template>
                        <service-export-mould
                            url="/technicalDisclosure/exportWord"
                            :requestParams="{ id: record.id }"
                            icon="cloud-download"
                            :serviceiUrl="faceApiUrl"
                            :isButton="false"
                        ></service-export-mould>
                    </template>
                    <!-- 删除 -->
                    <template v-btnPermission="'tm_012_del_03'" v-if="hideBuquBtn()">
                        <a class="del_btn" @click="handleRemove(record.id)">删除</a>
                    </template>
                    </MoreButton>
                </template>
                <template slot="status" slot-scope="text, record">
                    <list-status :status="record.status == 0 ? 'DRAFT' : 'SUBMITTED'" conversion="en" />
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { getPageTechnicalDisclosure, delTechnicalDisclosure,technicalDisclosureGetTotal} from '@/api/technical/technicalClarificaiton'
import BasePage from '@/views/basePage' // 基础配置
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商
import ServiceExportMould from '@/components/ServiceExportMould'
import { faceApiUrl } from '@/api/config.js'
const searchArr = [
    // 搜索框
    {
      name: '所属单位',
      valueKey: 'searchQuery',
      type: OrgTreeSelect,
    },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchCompanyId',
    //     type: SelectSubCompany
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchCompanyId',
    //     valueKey: 'projectId',
    //     type: SelectProject
    // },
    {
        name: '工程部位',
        type: 'input',
        value: 'floorName'
    },
    {
        name: '分部分项',
        type: 'input',
        value: 'subItemProjectName'
    },
    {
        name: '分包单位',
        keyValue: 'projectId',
        valueKey: 'subcontractorId',
        type: SelectSubcontractor
    },
    {
        name: '方案名称',
        type: 'input',
        value: 'programmeName'
    },
    {
        name: '交底时间',
        type: 'dateRange',
        value: 'activityDate',
        attr: {
            rangeFormat: ['disclosureStartTime', 'disclosureEndTime']
        }
    },
    {
        name: '状态',
        value: 'status',
        type: 'select',
        data: [
            {
                value: '0',
                label: '未提交'
            },
            {
                value: '1',
                label: '已提交'
            }
        ]
    }
]
const columns = [
    {
        title: '所属分公司',
        dataIndex: 'branchCompanyName'
    },
    {
        title: '所属项目',
        dataIndex: 'projectName'
    },
    {
        title: '工程部位',
        dataIndex: 'floorName',
        ellipsis: true,
        width: '200px'
    },
    {
        title: '分部分项',
        dataIndex: 'subItemProjectName',
        ellipsis: true,
        width: '200px'
    },
    {
        title: '方案名称',
        dataIndex: 'programmeName',
        ellipsis: true,
        width: '200px'
    },
    {
        title: '分包单位',
        dataIndex: 'subcontractorName'
    },
    {
        title: '分包负责人',
        dataIndex: 'subcontractorLeaderName'
    },
    {
        title: '交底时间',
        dataIndex: 'disclosureTime'
    },
    {
        title: '填报人',
        dataIndex: 'updateUserName'
    },
    {
        title: '填报时间',
        dataIndex: 'updateTime'
    },
    {
        title: '状态',
        dataIndex: 'status',

        scopedSlots: { customRender: 'status' }
    },
    {
        title: '操作',
        dataIndex: 'actions',
        width: '250px',
        align: 'center',
        fixed: 'right',
        scopedSlots: { customRender: 'actions' }
    }
]
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        ServiceExportMould
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {}, // 查询参数
            faceApiUrl: faceApiUrl,
            totalInfo:{},
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, { param: this.queryParam })
                this.getmeetingTotalReq(requestParameters) // 调用统计接口
                return getPageTechnicalDisclosure(requestParameters).then((res) => {
                    if (res.code === '0') {
                        res.data.list.forEach((i) => {
                            i.statusName = i.status == 1 ? '已提交' : '未提交'
                        })
                        return { code: 200, data: res.data.list, total: res.data?.total }
                    }
                })
            },
            removeApi: { remove: delTechnicalDisclosure }, // api
            customColumns: [
                { title: '所属分公司', dataIndex: 'branchCompanyName' },
                { title: '所属项目', dataIndex: 'projectName' },
                {title: '工程部位',dataIndex: 'floorName',},
                {title: '分部分项',dataIndex: 'subItemProjectName',},
                // { title: '楼栋号', dataIndex: 'floorName' },
                { title: '方案名称', dataIndex: 'programmeName' },
                { title: '分包单位', dataIndex: 'subcontractorName' },
                { title: '分包负责人', dataIndex: 'subcontractorLeaderName' },
                { title: '交底时间', dataIndex: 'disclosureTime' },
                { title: '填报人', dataIndex: 'updateUserName' },
                { title: '填报时间', dataIndex: 'updateTime' },
                { title: '状态', dataIndex: 'statusName' }
            ]
        }
    },
    methods: {
        // 获取统计信息
         async getmeetingTotalReq(extra = {}) {
            try {
                const params = extra.param 
                const res = await technicalDisclosureGetTotal(params)
                this.totalInfo = res.data || {}
            } catch(e) {
                console.error(e)
            }
        },
        // 搜索
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: 'updateTechnicalClarificaiton',
                query
            })
        },
             /**
         * 统计
         */
         statisticsTemp() {
          return (
            <span>
              <span>审批通过方案数：<a>{ this.totalInfo.complete || 0  }</a></span>
              <span> | 已交底方案数：<a>{this.totalInfo.submit  || 0  }</a></span>
              <span> | 未交底方案数：<a>{ this.totalInfo.undo || 0  }</a></span>
            </span>
          )
        }
    }
}
</script>
